<?php
//This controller handles the bookmarks that can be uploaded by any user on FullyJacked.com

session_start();
/**
 * Description of bookmarks
 *
 * @author bilde
 */
class bookmarks extends CI_Controller
{

	function  __construct()
        {
           parent::__construct();

        if (!$this->session->userdata('is_logged_in'))
        {
            redirect('/welcome/index','refresh');
        }


	}

        //Load bookmark-view and list all bookmarks by 'logged_in_user'.
	function index(){
		$data['title'] = 'List of Bookmarks';
		$data['main_content'] = 'bookmark/bookmark_home';
		$data['user'] = $this->session->userdata('id');
		$data['results'] = $this->model_bookmarks->list_bookmarks();
		//$data['bookmark_tags'] = $this->model_tags->list_tag_objects("bookmarks");
		//$data['comments'] = $this->model_comments->list_comments(array_keys($data['results']),'bookmarks');
		$data['usernames'] = $this->model_users->getAllUsernames();
		$this->load->vars($data);
		$this->load->view('includes/template');
	}

        //Load a view for tagget bookmark($id)
	function view_bookmark($id){
		$bookmark = $this->model_bookmarks->get_bookmark($id);
		$data['title'] = $bookmark->url;
		$data['main_content'] = 'bookmark/view_bookmark';
		$data['user'] = $this->session->userdata('id');
		$data['results'] = $bookmark;
		$data['usernames'] = $this->model_users->getAllUsernames();
		//$data['bookmark_tags'] = $this->model_tags->list_tag_objects_single($id,'bookmarks');
		//$data['comments'] = $this->model_comments->list_comments_single($id,'bookmarks');
		$this->load->vars($data);
		$this->load->view('includes/template');
	}

        //load view and list all bookmarks from bookmark-table.
	function all(){
		$data['title'] = 'Bookmark Directory';
		$data['main_content'] = 'bookmark/bookmarks_all';
		$data['results'] = $this->model_bookmarks->list_all_bookmarks();
		$data['user'] = $this->session->userdata('id');
		$data['usernames'] = $this->model_users->getAllUsernames();
		$this->load->vars($data);
		$this->load->view('includes/template');
	}

        //updates a bookmark in the bookmark-table.
	function update(){
		$data['url'] = prep_url($this->input->post('url'));
		$data['title'] = 'Add Bookmark';
		$data['main_content'] = 'bookmark/add_bookmark';
		$data['user'] = $this->session->userdata('id');
		$this->load->vars($data);
		$this->load->view('includes/template');

	}

        //add a bookmark to the bookmark-table.
	function insert(){

		$try = $this->model_bookmarks->add_bookmark();
		//$tags = xss_clean(substr($_SESSION['b_tags'],0,255));
		//$this->model_tags->add_tags($tags,'bookmarks',$try);

		redirect("bookmarks/index", 'refresh');
	}
}
?>
